﻿@model AgentListModel
@using Urs.Admin.Models.Agents
@using System.Globalization;

<style type="text/css">
    .laytable-cell-1-AvatarPictureUrl {
        height: 100%;
        max-width: 100%;
    }
</style>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        @await Component.InvokeAsync("AgentStatistics")
        <div class="layui-col-sm12">
            <div class="layui-card">
                <div class="layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form  layui-form-pane layui-card-header layuiadmin-card-header-auto">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <label class="layui-form-label">姓名</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="SearchShopName" id="SearchShopName" placeholder="姓名" autocomplete="off">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">昵称</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="SearchNickname" id="SearchNickname" placeholder="昵称" autocomplete="off">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <label class="layui-form-label">电话号码</label>
                                <div class="layui-input-inline">
                                    <input class="layui-input" name="SearchPhone" id="SearchPhone" placeholder="电话号码" autocomplete="off">
                                </div>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn" lay-submit lay-filter="LAY-app-contlist-search">筛选</button>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn  layui-btn-normal layuiadmin-btn-tags" lay-submit lay-filter="LAY-app-exportexcel">导出筛选数据</button>
                            </div>
                            <div class="layui-inline">
                                <button class="layui-btn layui-btn-normal layuiadmin-btn-tags" data-type="add" style="display:none;">添加</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="layui-card-body">
                    <table id="LAY-agents-list" lay-filter="LAY-agents-list"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="activeTpl">
    <span>{{ d.Approved ? '通过' : ''}}</span>
</script>
<script>
    layui.use(['index', 'table'], function () {
            var index = layer.load(2, { shade: false });
            var table = layui.table
                , form = layui.form;
        //分类管理
            table.render({
                elem: '#LAY-agents-list'
                , url: '@Html.Raw(Url.Action("List", "Agents"))' //模拟接口
                , method: 'post'
                , page: true //开启分页
                , even: true
                , limit: 15
                , limits: [15, 30, 50, 100]
                , cols: [[
                    { type: 'numbers' }
                    , { field: 'ShopName', title: '姓名', minWidth: 80 }
                    , { field: 'Nickname', title: '昵称', minWidth: 80 }
                    , { field: 'PhoneNumber', title: '电话', minWidth: 100, align: 'center' }
                    , { field: 'ChildNumber', title: '下级数量', minWidth: 80, align: 'center' }
                    , { field: 'Approved', title: '审核', templet: '#activeTpl', width: 120, align: 'center' }
                    , { field: 'Id', title: '分销用户', minWidth: 80, align: 'center', templet: '<div><a href="@Url.Action("Users")/{{d.Id}}">用户明细</a></div>' }
                    , { field: 'Id', title: '分销订单', minWidth: 80, align: 'center', templet: '<div><a href="@Url.Action("Orders")/{{d.Id}}">订单明细</a></div>' }
                    , { field: 'Id', title: '分红明细', minWidth: 80, align: 'center', templet: '<div><a href="@Url.Action("BonusItems")/{{d.Id}}">分红明细</a></div>' }
                ]]
                , id: 'testReload'
            , text: { none: '一条数据也没有^_^' }
            , done: function () {
                layer.close(index);
            }
            });
        //监听搜索
        layui.form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            //执行重载
            table.reload('testReload', {
                page: {
                    curr: 1 //重新从第 1 页开始
                }
                , where: field
            }, 'data');
        });

        //监听搜索
         layui.form.on('submit(LAY-app-exportexcel)', function (data) {
             var field = data.field;
             window.location.href = '@Url.Action("ExportExcelAll")?SearchShopName=' + field.SearchShopName + '&SearchNickname=' + field.SearchNickname + '&SearchPhone=' + field.SearchPhone
         });

        //监听工具条
        table.on('tool(LAY-agents-list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'del') {
                layer.confirm('确定删除？', function (index) {
                    obj.del();
                    $.post('@Url.Action("Delete")', { id: obj.data.Id });
                    layer.close(index);
                });

            } else if (obj.event === 'edit') {
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: '@Url.Action("Edit")?id=' + data.Id
                    , shade: 0.2
                    , maxmin: true
                    , shadeClose: true
                    , area: ['900px', '600px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        
                        var submit = layero.find('iframe').contents().find("#set_system_submit_btn");
                        submit.click();
                    }
                });
            }
        });

         //监听锁定操作
            form.on('switch(active)', function (obj) {
            var check = obj.elem.checked;
            $.post('@Url.Action("Active")', { Id: this.value, checked: check });
         })

        var $ = layui.$, active = {
            add: function () {
                layer.open({
                    type: 2
                    , title: '编辑'
                    , content: '@Url.Action("Edit")'
                    , shade: 0.2
                    , maxmin: true
                    , shadeClose: true
                    , area: ['900px', '600px']
                    , btn: ['确定', '取消']
                    , yes: function (index, layero) {
                        
                        var submit = layero.find('iframe').contents().find("#set_system_submit_btn");
                        submit.click();
                    }
                });
            }
        }
        $('.layui-btn.layuiadmin-btn-tags').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
    });
</script>







